import 'package:flutter/material.dart';

// void main() {
//   runApp(const MyApp());
// }
//
// class MyApp extends StatelessWidget {
//   const MyApp({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     return MaterialApp(
//       title: 'AnimatedContainer Demo',
//       home: const AnimatedContainerPage(),
//     );
//   }
// }

class AnimatedContainerPage extends StatefulWidget {
  const AnimatedContainerPage({super.key});

  @override
  State<AnimatedContainerPage> createState() => _AnimatedContainerPageState();
}

class _AnimatedContainerPageState extends State<AnimatedContainerPage> {
  bool _isChanged = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('AnimatedContainer 学习案例')),
      body: Center(
        child: AnimatedContainer(
          duration: const Duration(seconds: 1), // 动画时长
          curve: Curves.easeInOut,             // 动画曲线（缓入缓出）
          width: _isChanged ? 200 : 100,
          height: _isChanged ? 200 : 100,
          decoration: BoxDecoration(
            color: _isChanged ? Colors.blue : Colors.red,
            borderRadius: BorderRadius.circular(_isChanged ? 50 : 10),
          ),
          margin: EdgeInsets.only(top: _isChanged ? 100 : 20),
          child: const Center(
            child: Text(
              '点我变形',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _isChanged = !_isChanged; // 切换状态触发动画
          });
        },
        child: const Icon(Icons.play_arrow),
      ),
    );
  }
}
